package sc.prototype.pfs.eventnotify.model;

import java.util.regex.Pattern;

/**
 * 扩展参数
 */
public class ParamKey {

    public ParamKey(String key, String description, String validateRegex, boolean mandatory) {
        this.key = key;
        this.description = description;
        this.pattern = Pattern.compile(validateRegex);
        this.mandatory = mandatory;
    }

    /** 配置编码 */
    String key;

    /** 配置说明 */
    String description;

    /** 校验正则表达式 */
    Pattern pattern;

    /** 是否必填 */
    boolean mandatory;

    /**
     * 检查配置是否格式正确
     */
    public boolean checkPass(String input) {
        return pattern.matcher(input).find();
    }

    public String getKey() {
        return key;
    }

    public String getDescription() {
        return description;
    }

    public Pattern getPattern() {
        return pattern;
    }

    public boolean isMandatory() {
        return mandatory;
    }

    @Override
    public String toString() {
        return "ParamKey [key=" + key + ", desc=" + description + ", pattern=" + pattern + ", mandatory=" + mandatory
                + "]";
    }

}
